package com.aaa.ssm.controller;

import com.aaa.ssm.entity.Menu;
import com.aaa.ssm.entity.SysUser;
import com.aaa.ssm.service.MenuService;
import com.aaa.ssm.util.Page;
import com.aaa.ssm.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @ fileName:MenuController
 * @ description:
 * @ author:张圣福
 * @ createTime:2023/10/5 21:15
 * @ version:1.0.0
 */
@RestController //@Controller+@ResponseBody
@RequestMapping("menu")
public class MenuController extends BaseController{
    @Resource
    private MenuService menuService;
    /**
     * 查询所有树数据
     * @return
     */
    @GetMapping("queryAllTreeData")
    public Result queryAllTreeData(){
        return success(menuService.queryTreeData());
    }
    /**
     * 根据用户编号查询树数据
     * @param
     * @return
     */
    @GetMapping("queryTreeDataByUserId")
    public Result  queryTreeDataByUserId(HttpSession session){
        Integer userId = ((SysUser) session.getAttribute("userInfo")).getUserId();
        return success(menuService.queryTreeDataByUserId(userId));
    }



    /**
     * 分页查询
     * @param page
     * @return
     */
    @PostMapping("queryByPage")
    @ResponseBody
    public Result queryByPage(@RequestBody Page<Menu> page){
        return success(menuService.queryByPage(page));
    }

    /**
     * 查询所有
     * @param menu
     * @return
     */
    @GetMapping("queryByParam")
    public Result queryByParam(@RequestBody Menu menu){
        List<Menu> patientList=menuService.queryByParam(menu);
        return success(patientList);
    }

    /**
     * 通过Id查询
     * @param menuId
     * @return
     */

    @GetMapping("queryById")
    public Result queryById(Integer menuId){
        return success(menuService.queryById(menuId));
    }

    /**
     * 添加
     * @param menu
     * @return
     */
    @PutMapping("add")
    private Result add(@RequestBody Menu menu){
        return success(menuService.add(menu));
    }

    /**
     * 更新
     * @param menu
     * @return
     */
    @PutMapping("update")
    @ResponseBody
    private Result update(@RequestBody Menu menu){
        return success(menuService.update(menu));
    }

    /**
     * 删除用户
     * @param menuId
     * @return
     */
    @DeleteMapping("delete")
//    @ResponseBody
    private Result delete(Integer menuId){

        return  success(menuService.delete(menuId));
    }
}
